<?php
/**
 *  Ajax 请求处理部分
 *
 *  Authors: 小照
 *  Mailbox: 2453162656@qq.com
 *
 */
include_once ('state.php');
$row = $DB->get_row("select * FROM " . DBQZ . "_user where uid ='".$userrow['uid']."' limit 1"); //获取用户信息

/******************* Redis检查频繁请求访问 *******************/
if($conf['check']==1){
	$user_id = real_ip();
	$valid_time = intval($conf['check_time'])?intval($conf['check_time']):10;
	$redis = new Redis();//创建对象
	$redis->connect('127.0.0.1',6379);//建立连接
	if (!$redis->exists($user_id)){ //判断用户是否有访问过, 没有进行存储
		$redis->setex($user_id,$valid_time,1);
	}else{
		$count = $redis->incr($user_id);  //增值 1
		$ttl = $redis->ttl($user_id);  //获取键到期的剩余时间(秒)
		$pass_time = $valid_time - $ttl;
		if ($pass_time <= 10){
			if ($count > 2){
				$arr = array(
					'code' 	=> 0,
					'msg' 	=> '访问频繁,请稍后重试!',
					'data' 	=> array(
						'src' => ''
					)
				);
				echo json_encode($arr); die;  //输出
			}
		}
	}
}
	
/******************* Redis检查频繁请求访问 *******************/

$my = isset($_POST['my'])?$_POST['my']:$_GET['my'];
switch ($my) {
	case 'infoedit': # 更改账号资料
		$pwd 	= $_POST['pwd'];
		$mail 	= $_POST['mail'];
		$qq 	= $_POST['qq'];
		if(!$row_edit=$DB->get_row("select * from `". DBQZ ."_user` where `uid`={$row['uid']}")){
			addlog('试图篡改uid访问更改资料界面');
			$arr = array(
				'code' => 0,
				'msg'  => '账号不存在'
			);
		}elseif($pwd==''){
			$pwd 	= $row['pwd'];
		}else{
			$pwd 	= md5($pwd);
		}
		$sql = $DB->query("UPDATE `". DBQZ ."_user` SET `pwd`='{$pwd}', `mail`='{$mail}', `qq`='{$qq}' where `uid`={$row_edit['uid']}");
		if($sql){
			addlog($row_edit['user'].' 更改了账号资料');
			$arr = array(
				'code' => 1,
				'msg' => '修改成功'
			);
		}else{
			$arr = array(
				'code' => 0,
				'msg' => '修改失败'
			);
		}
		echo json_encode($arr); die;
	break;
	
	
default: 
	# code...
break;
}